var str = "abcdf";
function reverseStr(str) {
    let length = str.length;
    if (length < 2) return str;
    let res = "";
    for (let i = length - 1; i >= 0; i--) {
        res += str.charAt(i);
    }
    return res;
}

var res = reverseStr(str);
console.log(res);
